package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import pojo.Area;
import util.DbUtil;
import util.DbUtil.ConnType;
import dao.AreaDao;

public class AreaDaoImpl implements AreaDao{

	Connection conn;
	
	@Override
	public List<Area> findAll() {
		return null;
	}

	@Override
	public List<Area> findAll(String areaName) {
		List<Area> list = new ArrayList<Area>();
		if(areaName==null || areaName.trim().length()==0){
			return null;
		}
		PreparedStatement ps = null;
		try {
			conn = DbUtil.createConnection(ConnType.JDBC_ORACLE);
			String sql = "select area from areas where area like('%"+ areaName +"%')";
			ps = conn.prepareStatement(sql);
			ResultSet set = ps.executeQuery();
			while(set.next()){
				Area area = new Area();
				area.setArea(set.getString("area"));
				list.add(area);
			}
			return list;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		} finally{
			DbUtil.close(conn, ps, null);
		}
	}

}
